<#assign tableName="${table.comment?replace('信息','')?replace('表','')}"/>
<#assign entityCap="${entity?cap_first}"/>
<template>
  <div class="entityCap">
    <page-search
      :searchFormConfig="searchFormConfig"
      @resetBtnClick="handleResetClick"
      @queryBtnClick="handleQueryClick"
    />
    <page-content
      ref="pageContentRef"
      :contentTableConfig="contentTableConfig"
      pageName="${entityCap}"
      title="${tableName}"
      @newBtnClick="handleNewData"
      @editBtnClick="handleEditData"
    ></page-content>

    <page-modal
      :defaultInfo="defaultInfo"
      ref="pageModalRef"
      :modalConfig="modalConfig"
      :title="modal.title"
      pageName="${entityCap}"
      @refreshData="handleResetClick"
    ></page-modal>
  </div>
</template>

<script lang="ts">
import { searchFormConfig } from './config/search.config'
import { contentTableConfig } from './config/content.config'
import { modalConfig } from './config/modal.config'

import PageSearch from '@/components/page-search'
import PageContent from '@/components/page-content'
import PageModal from '@/components/page-modal'

import { defineComponent, reactive } from 'vue'

import { usePageSearch } from '@/hooks/use-page-search'
import { usePageModal } from '@/hooks/use-page-modal'

export default defineComponent({
  components: { PageSearch, PageContent, PageModal },
  setup() {
    const [pageContentRef, handleResetClick, handleQueryClick] = usePageSearch()

    let modal = reactive({
      title: '新建${tableName}'
    })

    const newCallback = () => {
      //新增
      modal.title = '新建${tableName}'
    }
    const editCallback = () => {
      //编辑
      modal.title = '编辑${tableName}'
    }

    const [pageModalRef, defaultInfo, handleNewData, handleEditData] =
      usePageModal(newCallback, editCallback)

    return {
      pageContentRef,
      searchFormConfig,
      contentTableConfig,
      handleResetClick,
      handleQueryClick,
      pageModalRef,
      defaultInfo,
      handleNewData,
      handleEditData,
      modalConfig,
      modal
    }
  }
})
</script>

<style scoped lang="less"></style>
